<template>
  <div class="home_winning">
    <div class="card_list_box" v-if="rankList.length">
      <ul :class="['card_title', props.isGameDetail ? 'card_title1' : '']">
        <li :class="['title_left', props.isGameDetail ? 'title_left1' : '']">
          <ImgT style="width:18px;height:18px;margin-right: 5px;" src="/imgs/home/zhongjiang.webp" alt="" />
          <span>{{ t("home_page_winning") }}</span>
        </li>
        <li class="title_right">
          <p class="more" @click="goMore">
            {{ t('home_page_more') }}
          </p>
          <!-- <div class="swiper-btn swiper_pre" :class="{ disabled: isWinningBeginning || list.length === 0 }"
            @click="otherHandlePrev(winningRef, 'winning')">
            <iconpark-icon name="zuo-keyong" size="24" />
          </div>
          <div class="swiper-btn swiper_next" :class="{ disabled: isWinningEnd || list.length === 0 }"
            @click="otherHandleNext(winningRef, 'winning')">
            <iconpark-icon name="you-keyong" size="24" />
          </div> -->
        </li>
      </ul>
      <Marquee direction="reverse" :duration="50">
        <div v-for="(group, i) in rankList" :key="i" class="winning_list_li" @click.stop="toDetail(group)">
          <ImgT :key="group.picture_h5" :src="joinURL(settings.backend_upload, group.picture_h5)" alt="" />
          <span class="name">{{ group.nickname }}</span>
          <span class="money">{{ formatBigNumberK(group.money) }}</span>
        </div>
      </Marquee>
    </div>
  </div>
</template>

<script setup lang="ts">
import { joinURL } from '@/utils/publicMethods'
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import Marquee from '@/components/Marquee.vue'
import { formatBigNumberK } from "@/utils/publicMethods";
import { storeToRefs } from "pinia";
import { Page } from "@/store/page";
import pinia from "@/store";
import router from "@/router";
import { useRecentWin } from '@/views/recentWin/hooks/useRecentWin';

const { settings } = storeToRefs(Page(pinia));
const props = defineProps({
  isGameDetail: {
    type: Boolean,
    default: false
  },
})

const { t } = useI18n();

const { list, init, toDetail } = useRecentWin()
init()

const rankList = computed(() => {
  return list.value.filter((_, i) => i < 50); //chunkArray(list.value.filter((_, i) => i < 5), 5)
})

function goMore() {
  router.push({
    path: '/recentWin'
  })
}
</script>

<style lang="scss" scoped>
.home_winning {
  .card_list_box {
    padding-left: 14px;

    .card_title {
      display: flex;
      padding: 12px 14px 12px 0;
      justify-content: space-between;
      align-items: center;
      line-height: 24px;

      .title_left {
        font-family: PingFang SC;
        font-size: 14px;
        font-weight: 600;
        line-height: 16px;
        text-align: left;
        color: #fcfffa;
        display: flex;
        justify-content: space-between;
        align-items: center;

        img {
          width: 18px;
          height: 18px;
          margin-right: 5px;
        }
      }

      .title_left1 {
        font-family: PingFang SC;
        font-size: 12px;
        font-weight: 500;
        line-height: 12px;
        text-align: left;
        color: #C6C4F5;
        display: flex;
      }

      .title_right {
        font-family: PingFang SC;
        font-size: 12px;
        font-weight: 500;
        color: #C6C4F5;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 24px;

        .more {
          background: #282747;
          // margin-left: 8px;
          // height: 100%;
          line-height: 24px;
          padding: 0px 6px;
          border-radius: 6px;
          box-shadow: 0.5px 0.5px 1px 0px #4B4A6E inset;
        }

        .swiper-btn {
          position: relative;
          top: 4px;
          margin-left: 8px;
        }

        .disabled {
          pointer-events: none;
          opacity: 0.5;
          cursor: not-allowed;
        }
      }
    }

    .card_title1 {
      padding: 0 4px 0 0;
    }

    .winning_list_li {
      width: 64px;
      height: 96px;
      margin-right: 8px;
      border-radius: 8px;
      background: #131232;
      box-sizing: border-box;
      padding: 4px;
      // box-shadow: 0.5px 0.5px 1px 0px #2e296b inset;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;

      img {
        width: 56px;
        height: auto;
        border-radius: 8px;
      }

      .money {
        text-align: left;
        color: #ED8302;
        font-family: "SF Pro Display";
        font-size: 10px;
        font-style: normal;
        font-weight: 700;
        line-height: 10px;
        /* 100% */
      }

      .name {
        width: 100%;
        font-family: "PingFang SC";
        font-style: normal;
        font-size: 10px;
        font-weight: 500;
        line-height: 10px;
        text-align: center;
        // overflow: hidden;
        // text-overflow: ellipsis;
        white-space: nowrap;
        color: #A8A8CA;
      }
    }

    .masking_layer {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      backdrop-filter: blur(1px);
      background: rgba(0, 0, 0, 0.6);
      font-family: PingFang SC;
      font-size: 12px;
      font-weight: 500;
      line-height: 18px;
      color: #ffffff;

      .maskin_img {
        width: 32px;
        height: 32px;
        margin-bottom: 8px;
      }
    }
  }
}

:deep(.swiper-wrapper) {
  transition-timing-function: linear !important;
}
</style>
